package com.example.hrmsaas.system.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单树构造器
 */
public class TreeNodesBuilder {

    public static List<TreeNode> builder(List<TreeNode> treeNodes, int pid) {

        List<TreeNode> nodes = new ArrayList<TreeNode>();
        for (TreeNode n1 : treeNodes) {
            if (n1.getPid() < pid) {
                continue;
            }
            if (n1.getPid() == pid) {
                nodes.add(n1);
            }
            for (TreeNode n2 : treeNodes) {
                if (n2.getPid() == n1.getId()) {
                    n1.getChildren().add(n2);
                }
            }
        }
        return nodes;
    }
}
